<?php

/**
 * 文本多语言列表
 * @BelongProject: flami_mangers
 * @CreateTime: 2025-10-30 19:27:39
 * @Description: TODO
 */

namespace app\admin\logic;

use app\admin\model\LangTextModel;

class LangTextLogic
{
    private $textTypeArr = [
        [
            'type' => 'popupTitle',
            'name' => '弹框标题'
        ],
        [
            'type' => 'popupContent',
            'name' => '弹框内容'
        ],
        [
            'type' => 'bottomProtocolName',
            'name' => 'APP登录界面底部协议标题'
        ],
        [
            'type' => 'privacyPolicyName',
            'name' => '隐私政策名称'
        ],
        [
            'type' => 'privacyPolicyUrl',
            'name' => '隐私政策跳转链接'
        ],
        [
            'type' => 'serviceAgreementName',
            'name' => '服务协议名称'
        ],
        [
            'type' => 'serviceAgreementUrl',
            'name' => '服务协议跳转链接'
        ],
    ];


    /**
     * 获取数据
     * @param $params
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getData($params): \think\Paginator
    {
        $condition = [
            'del_flag' => 0
        ];

        if (!empty($params['langId'])) {
            $condition['lang_id'] = $params['langId'];
        }
        $model = new LangTextModel();
        $query = $model->where($condition);
        $list = $query->order('id desc')->paginate(20);
        $textTypeMap = array_column($this->textTypeArr, 'name','type');

        foreach ($list as $k => &$v) {
            if (isset($textTypeMap[$v['type']])) {
                $v['typeName'] = $textTypeMap[$v['type']];
            }
        }

        return $list;
    }

    /**
     * 获取多语言文本类型
     * @return array[]
     */
    public function getTypeArr(): array
    {
        return $this->textTypeArr;
    }


}